package org.mat.ipaas.ucenter.bff.admin.modules.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysCheckRuleRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysCheckRuleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * 编码校验规则
 */
@Slf4j
@Api(tags = "编码校验规则")
@RestController
@RequestMapping("/sys/checkRule")
public class SysCheckRuleController {

    @Autowired
    private SysCheckRuleRestAPI sysCheckRuleRestAPI;

    /**
     * 分页列表查询
     *
     * @param sysCheckRuleDTO
     * @param pageNo
     * @param pageSize
     * @param request
     * @return
     */
    @ApiOperation(value = "编码校验规则-分页列表查询", notes = "编码校验规则-分页列表查询")
    @GetMapping(value = "/list")
    public MatApiResponse queryPageList(
            SysCheckRuleDTO sysCheckRuleDTO,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.queryPageList(sysCheckRuleDTO, pageNo, pageSize);
        return matApiResponse;
    }


    /**
     * 通过id查询
     *
     * @param ruleCode
     * @return
     */
    @ApiOperation(value = "编码校验规则-通过Code校验传入的值", notes = "编码校验规则-通过Code校验传入的值")
    @GetMapping(value = "/checkByCode")
    public MatApiResponse checkByCode(
            @RequestParam(name = "ruleCode") String ruleCode,
            @RequestParam(name = "value") String value
    ) throws UnsupportedEncodingException {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.checkByCode(ruleCode, value);
        return matApiResponse;
    }

    /**
     * 添加
     *
     * @param sysCheckRuleDTO
     * @return
     */
    @ApiOperation(value = "编码校验规则-添加", notes = "编码校验规则-添加")
    @PostMapping(value = "/add")
    public MatApiResponse add(@RequestBody SysCheckRuleDTO sysCheckRuleDTO) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.add(sysCheckRuleDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysCheckRuleDTO
     * @return
     */
    @ApiOperation(value = "编码校验规则-编辑", notes = "编码校验规则-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse edit(@RequestBody SysCheckRuleDTO sysCheckRuleDTO) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.edit(sysCheckRuleDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编码校验规则-通过id删除", notes = "编码校验规则-通过id删除")
    @DeleteMapping(value = "/delete")
    public MatApiResponse delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "编码校验规则-批量删除", notes = "编码校验规则-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编码校验规则-通过id查询", notes = "编码校验规则-通过id查询")
    @GetMapping(value = "/queryById")
    public MatApiResponse queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 导出excel
     *
     * @param sysCheckRuleDTO
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysCheckRuleDTO sysCheckRuleDTO) {
        ModelAndView modelAndView = sysCheckRuleRestAPI.exportXls(sysCheckRuleDTO);
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse importExcel() {
        MatApiResponse matApiResponse = sysCheckRuleRestAPI.importExcel();
        return matApiResponse;
    }

}
